#ifndef __MEDIA_IPC_MESG_H__
#define __MEDIA_IPC_MESG_H__

#include <stdint.h>
#include <pthread.h>
#include <stdbool.h>
#include <sys/un.h> 
#include <sys/socket.h>

//--------------------------------------------------------------------------
#define ID_UI		0x20
#define ID_IMAGE	0x21

//-------------------------------------------------------------------------------
#define CMD_READ		0x22
#define CMD_WRITE		0x33

//-------------------------------------------------------------------------------
#define WAIT_TIME		500
#define CNT_WAIT_1S		(1000 / WAIT_TIME)

#define WT_SUCCESS			0x00 	// �ɹ�

#define WT_ERR_COMM_HEADER	0x10 	// ͨѶЭ��ͷ����
#define WT_ERR_COMM_LENGTH	0x11 	// ͨѶ���ݳ��ȴ���
#define WT_ERR_COMM_CRC		0x12 	// ͨѶ����У�����

#define WT_ERR_COMM_DATA	0x20 	// ͨѶ���ݴ���
#define WT_ERR_COMM_DLEN	0x21 	// ͨѶ���ݳ��ȴ���
#define WT_ERR_COMM_OPER	0x22 	// ͨѶ����ִ�д���

#define WT_DELAY_ACK		0x88    //ͨѶ�ɹ������ظ�
//--------------------------------------------------------------------------
#define MAX_RX_BUF_CNT		2
#define MAX_CMD_BUF_CNT		6
#define MAX_PORT_BUF_LEN	1024

//--------------------------------------------------------------------------
enum video_mode {
	VIDEO_MODE_PREVIEW = 0, //Ԥ��ģʽ
	VIDEO_MODE_REVIEW,      //�ط�ģʽ
};

//--------------------------------------------------------------------------
enum  video_rotator {

	VIDEO_ROTATOR_ANGLE0  = 0,
	VIDEO_ROTATOR_ANGLE45,
	VIDEO_ROTATOR_ANGLE90,
	VIDEO_ROTATOR_ANGLE135,
	VIDEO_ROTATOR_ANGLE180,
	VIDEO_ROTATOR_ANGLE225,
	VIDEO_ROTATOR_ANGLE270,
	VIDEO_ROTATOR_ANGLE315,

	MAX_VIDEO_ROTATOR_COUNT ,
};

//--------------------------------------------------------------------------
enum video_scale_up {
	VIDEO_SCALE_UP_x1 = 0, //ʼͼ��
	VIDEO_SCALE_UP_x2,	   //�Ŵ�1��
	VIDEO_SCALE_UP_x3,     //�Ŵ�2��
	VIDEO_SCALE_UP_x4,     //�Ŵ�3��

	MAX_VIDEO_SCALE_UP_STEP,
};

enum video_mirror {
	VIDEO_mirror_x1 = 0, 
	VIDEO_mirror_x2,
	VIDEO_mirror_x3,
	VIDEO_mirror_x4,
};

enum video_replay {
	VIDEO_REPLAY_STOP = 0, //��Ƶ�ط���ͣ
	VIDEO_REPLAY_START,    //ʱ���طſ�ʼ
};

enum media_replay_type {
	MEDIA_REPLAY_STOP,
	MEDIA_REPLAY_START,
	MEDIA_REPLAY_PAUSE,

};

//--------------------------------------------------------------------------
enum media_cmd_type {
	MEDIA_CMD_MODE_SWITCH = 0x10, 
	MEDIA_CMD_VIDEO_SCALE, 
	MEDIA_CMD_ROTATER,
	MEDIA_CMD_AUTOUP,
	MEDIA_CMD_WHITEBLACK, 
	MEDIA_CMD_MIRROR, 
	MEDIA_CMD_PHOTO, 
	MEDIA_CMD_RECORD_START, 
	MEDIA_CMD_RECORD_STOP,
	MEDIA_CMD_REPLAY, 
	MEDIA_CMD_MEDIA_PROC, 
	MEDIA_CMD_CAMERA_STATE, 
	MEDIA_CMD_RECORDING, 
	MEDIA_CMD_AB_PLAY, 

	MEDIA_ACK_RECORD_DURATION,
	MEDIA_ACK_REPLAY_DURATION,

	MAX_MEDIA_CMD_COUNT,
};

//--------------------------------------------------------------------------
struct media_cmd_oper {
	char cmd_str[30];
	int (*oper)(void* buffer, int size);
};


//--------------------------------------------------------------------------
typedef struct
{
	uint8_t recv_buf[MAX_PORT_BUF_LEN];

	int rx_idx;
	int rx_len;
	uint8_t rx_data[MAX_RX_BUF_CNT][MAX_PORT_BUF_LEN];

	int cmd_idx;
	int cmd_len[MAX_CMD_BUF_CNT];
	uint8_t cmd_data[MAX_CMD_BUF_CNT][MAX_PORT_BUF_LEN];

	int tx_len;
	uint8_t tx_data[MAX_PORT_BUF_LEN];

} tsPortDataCtrl;

//--------------------------------------------------------------------------
typedef struct
{
	int id;
	struct sockaddr_un sun_addr;
} tsIdAddr;

extern int media_cmd_eventloop(int msec);
extern void media_cmd_eventloop_quit(void);
extern int ack_video_photo(int state);
extern int ack_video_record(enum media_cmd_type cmd, int state);
extern int ack_video_scale(int state);
extern int ack_video_rotater(int state);
extern int ack_video_whiteblack(int state);
extern int ack_video_mirror(int state);
extern int ack_video_ab_play(int state);

extern int ack_video_repaly(int state, enum media_replay_type replay_type);
extern int ack_camera(int state);
extern int ack_get_file_proc(int state, uint8_t* file_proc, int size);
extern int ack_replay_duration(uint16_t duration_sec);
extern int ack_record_duration(uint16_t duration_sec);
extern int ack_camera(int state);

#endif
